package com.utils;

import android.text.Layout;
import android.text.Selection;
import android.widget.EditText;

/**
 * Created by Administrator on 2019/5/9.
 */

public class TextViewUtils {
    /**
     * 获取光标所在行数
     * @param editText
     * @return
     */
    public static int getCurrentCursorLine(EditText editText) {
        int selectionStart = Selection.getSelectionStart(editText.getText());
        Layout layout = editText.getLayout();
        if (selectionStart != -1) {
            return layout.getLineForOffset(selectionStart) + 1;
        }
        return -1;
    }
}
